package websocket.controller;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import websocket.dto.ResultDTO;
import websocket.dto.ResultList;
import websocket.entity.Ldmzjz;
import websocket.entity.dto.LdmzjzDTO;
import websocket.service.LdmzjzService;
import websocket.util.DateUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LdmzjzController
 * @Des TODO 雷达瞄准点校准
 * @Author lg
 * @Date 2022/6/22 13:00
 * @Version 1.0.0
 **/
@RestController
@RequestMapping("/api/ldmzjz")
public class LdmzjzController {

    @Autowired
    private LdmzjzService ldmzjzService;

    /**
     * 获取数据集 - postman测试通过
     */
    @GetMapping("/list")
    @ApiOperation("获取数据集")
    public ResultList<Ldmzjz> list() {
        List<Ldmzjz> list = ldmzjzService.list();
        return ResultList.success(list);
    }


    /**
     * 保存数据 - postman测试通过
     *
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("保存数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "雷达瞄准点校准分析结果数据", required = true, dataType = "Ldmzjz", paramType = "body")
    })
    public ResultDTO save(@RequestBody List<Ldmzjz> list) {
        List<Ldmzjz> batch = new ArrayList<>();
        list.forEach(item->{
            if (item.getXb() == null || item.getYb() == null || item.getZb() == null) {
                return;
            }
            item.setCreatTime(DateUtil.getCurrentTime());
            batch.add(item);
        });
        ldmzjzService.saveBatch(batch);
        return ResultDTO.success(null);
    }


    /**
     * 分析数据 - postman测试通过
     *
     * @return
     */
    @PostMapping("/analysis")
    @ApiOperation("分析数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "雷达瞄准点校准分析结果数据", required = true, dataType = "LdmzjzDTO", paramType = "body")
    })
    public ResultList<LdmzjzDTO> analysis(@RequestBody List<LdmzjzDTO> list) {
        if (list.isEmpty()) {
            return ResultList.success(null);
        }
        return ldmzjzService.analysis(list);
    }

    /**
     * 计算设备数据值 - postman测试通过
     *
     * @return
     */
    @PostMapping("/calsulationSheBeiZhi")
    @ApiOperation("计算设备数据值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "雷达瞄准点校准分析结果数据", required = true, dataType = "LdmzjzDTO", paramType = "body")
    })
    public ResultList<LdmzjzDTO> calsulationSheBeiZhi(@RequestBody List<LdmzjzDTO> list) {
        if (list.isEmpty()) {
            return ResultList.success(null);
        }
        return ldmzjzService.calsulationSheBeiZhi(list);
    }
}
